package com.cn.goodsadmin.observer;

import com.cn.goodsadmin.common.observes.IObservesr;
import com.cn.goodsadmin.common.observes.Message;
import com.cn.goodsadmin.common.observes.MessageConfig;
import com.cn.goodsadmin.common.observes.MessageManager;
import com.cn.goodsadmin.service.ActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component("UpdateFixtimeObserver")
public class UpdateFixtimeObserver implements IObservesr {

    @Autowired
    ActionService actionService;

    @PostConstruct
    public void init() {
        MessageManager.getInstanceMessage().registerMessage(this, MessageConfig.FIXTIMEACTIONUPDATE);
        System.out.println("init UpdateFixtimeObserver");
    }

    //  how  validate the  destory method is  a question
    @PreDestroy
    public void cleanUp() {
        MessageManager.getInstanceMessage().unRegisterMessage(this, MessageConfig.FIXTIMEACTIONUPDATE);
        System.out.println("cleanUp");
    }
    public void onNoticeMessage(Message message) {
        UpdateFixtimeMessage  updateFixtimeMessage=(UpdateFixtimeMessage)message;
        actionService.updateFixTime(updateFixtimeMessage.action);
    }
}
